import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//这行代码非常重要一定要写上，且"/"不能省略
@WebServlet("/MyHello")
public class MyHello extends HttpServlet {
//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        //默认会调用父类方法，一定要删除这行代码，否则会出错。
//        //super.doGet(req, resp);
//        //在构造响应body前将content-Type修改为浏览其识别的html并同一idea和浏览器的编码方式
//        resp.setContentType("text/html;charset=utf8");
//        //在Tomcat服务器页面中输出语句
//        System.out.println("hello Tomcat Get");
//        //在网页中中输出一条语句
//        resp.getWriter().write("响应body:helleo servlet");
//    }




    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doPost(req, resp);
        System.out.println("hello Tomcat Post");
        //在构造响应body前将content-Type修改为浏览其识别的html并同一idea和浏览器的编码方式
        resp.setContentType("text/html;charset=utf8");

        resp.getWriter().write("响应body:doPost");
    }

    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doPut(req, resp);
        System.out.println("hello Tomcat Put");
        //在构造响应body前将content-Type修改为浏览其识别的html并同一idea和浏览器的编码方式
        resp.setContentType("text/html;charset=utf8");

        resp.getWriter().write("响应body:doPut");
    }

    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doDelete(req, resp);
        System.out.println("hello Tomcat Delet");
        //在构造响应body前将content-Type修改为浏览其识别的html并同一idea和浏览器的编码方式
        resp.setContentType("text/html;charset=utf8");

        resp.getWriter().write("响应body:doDelet");
    }
}
